package dao.impl;

import java.util.Date;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import dao.ProjectManagerDao;
import pojo.MissionRelations;
import pojo.Missions;
import pojo.ProjectMissions;
import pojo.Users;
import pojo.view.ProjectDynmic;
import pojo.view.ProjectUser;
import pojo.view.ScoreProjectUser;

public class ProjectManagerDaoImpl implements ProjectManagerDao {
	
	
	private SqlSessionTemplate sqlSessionTemplate;
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}

//	@Override
//	public List<Users> projectUserFenYe(int projectteamUserNowNo, int projectid) {
//		// TODO Auto-generated method stub
//		Object object=new Object[]{projectid,(projectteamUserNowNo-1)*4};
//		return sqlSessionTemplate.selectList("projectUserFenYe", object);
//	}
//
//	@Override
//	public List<Users> getAllProjectUserByProjectId(int projectid) {
//		// TODO Auto-generated method stub
//		return sqlSessionTemplate.selectList("getAllProjectUserByProjectId",projectid);
//	}
//
//	@Override
//	public List<ProjectMission> getAllProjectMissionByProjectId(int projectid) {
//		// TODO Auto-generated method stub
//		return sqlSessionTemplate.selectList("getAllProjectMissionByProjectId",projectid);
//	}
//
//	@Override
//	public void addProjectMission(String missionName, String description, int urpid) {
//		// TODO Auto-generated method stub
//		System.out.println("addProjectMissionDAO");
//		Object object=new Object[]{missionName,description,urpid};
//		sqlSessionTemplate.insert("addProjectMission",object);
//	}
//	
//
//	@Override
//	public ProjectMission getProjectMissionByProMisId(int projectmissiontid) {
//		// TODO Auto-generated method stub
//		return sqlSessionTemplate.selectOne("getProjectMissionByProMisId",projectmissiontid);
//	}
	@Override
	public List<Users> projectUserFenYe(int projectteamUserNowNo, int projectid) {
		// TODO Auto-generated method stub
		Object object=new Object[]{projectid,(projectteamUserNowNo-1)*4};
		return sqlSessionTemplate.selectList("projectUserFenYe", object);
	}

	@Override
	public List<Users> getAllProjectUserByProjectId(int projectid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("getAllProjectUserByProjectId",projectid);
	}

	@Override
	public List<ProjectMissions> getAllProjectMissionByProjectId(int projectid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("getAllProjectMissionByProjectId",projectid);
	}


	@Override
	public ProjectMissions getProjectMissionByProMisId(int projectmissiontid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("getProjectMissionByProMisId",projectmissiontid);
	}

	@Override
	public void addRelationalTable(MissionRelations mr) {
		System.out.println("dao层的mr内容是"+mr.toString());
		// TODO Auto-generated method stub
		sqlSessionTemplate.insert("addRelationalTable",mr);
	}

	@Override
	public void addProjectMissionAndGetId(ProjectMissions projectmission) {
		// TODO Auto-generated method stub
		System.out.println("addProjectMissionDAO");
		//Object object=new Object[]{projectmission.getMissionName(),projectmission.getDescription(),projectmission.getUrpid()};
		sqlSessionTemplate.insert("addProjectMissionAndGetId", projectmission);
	}

	@Override
	public int getUrpIdByProMisId(int projectmissiontid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("getUrpIdByProMisId", projectmissiontid);
	}

	@Override
	public int getProjectIdByUrpId(int urpid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectOne("getProjectIdByUrpId", urpid);
	}

	@Override
	public void addMissionAndGetId(String missionName, String description, Date timestamp, int urpid, int projectmissiontid) {
		// TODO Auto-generated method stub
		Object object=new Object[]{missionName, description, timestamp, urpid, projectmissiontid};
		sqlSessionTemplate.insert("addMissionAndGetId", object);
	}

	@Override
	public List<Missions> getAllMissionByProMisId(int projectmissiontid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("getAllMissionByProMisId",projectmissiontid);
	}

	@Override
	public List<ProjectUser> getAllUsersByProjectId(int projectid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("getAllUsersByProjectId", projectid);
	}

	@Override
	public int getUrpIdByUidAndPid(int userid, int projectid) {
		// TODO Auto-generated method stub
		Object object=new Object[]{userid,projectid};
		return sqlSessionTemplate.selectOne("getUrpIdByUidAndPid", object);
	}

	@Override
	public ScoreProjectUser getScoreUserByUrpId(int urpid) {
		ScoreProjectUser scoreProjectUser =sqlSessionTemplate.selectOne("getScoreUserByUrpId", urpid);
		int allocatedMissionNB=sqlSessionTemplate.selectList("getMissionByUrpid",urpid).size();
		int completeddMissionNB=sqlSessionTemplate.selectList("getComMissionByUrpid",urpid).size();
		scoreProjectUser.setAllocateMissionNB(allocatedMissionNB);
		scoreProjectUser.setCompletedMissionNB(completeddMissionNB);
		// TODO Auto-generated method stub
		return scoreProjectUser;
	}

	@Override
	public void scoreProMember(int urpid, int subjectivescore) {
		// TODO Auto-generated method stub
		Object object=new Object[]{subjectivescore,urpid};
		sqlSessionTemplate.update("scoreProMember",object);
	}

	/*@Override
	public List<Users> getAllProjectUserByProjectId() {
		// TODO Auto-generated method stub
		
		return sqlSessionTemplate.selectList("getAllProjectUserByProjectId");
	}*/
	@Override
	public List<ProjectDynmic> getAllProjectDynamic(int projectid) {
		// TODO Auto-generated method stub
		System.out.println("动态列表长度："+sqlSessionTemplate.selectList("getAllProjectDynamic", projectid).size());
		return sqlSessionTemplate.selectList("getAllProjectDynamic", projectid);
	}

	@Override
	public int updatePMtoUnCompleted(int projectmissiontid) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.update("updatePMtoUnCompleted",projectmissiontid);
	}

}
